In this set of exercises, we will 1) make sure that you can use Git from within RStudio and 2) clone and work on the GitHub repository you have created in the previous session.
Note: You can find the solutions for this exercise as well as the following ones in the solutions folder within the workshop materials.
Git.
Git installation via Tools -> Global Options -> Git/SVN. If the menu displays the location of a Git executable, everything should work. If this is not the case, you may need to point RStudio to the location of your Git executable. You can find some further information on this in the troubleshooting section RStudio, Git, GitHub Hell of Happy Git and GitHub for the useR.
R and RStudio.
R package.
# Option 1: While logged in to your GitHub account go to https://github.com/settings/tokens,
# click "Generate token", and select "gist", "repo", "user", and "workflow" as scopes.
# Option 2
library(usethis)
create_github_token()
R/RStudio.
gitcreds package (which should be installed together with usethis) provides a function for this.
library(gitcreds)
gitcreds_set()
Git via RStudio and have created and stored a PAT for authentication via HTTPS, we can now clone and work on the GitHub repository we have created in the previous session. When doing this, you should also create a new RStudio project.
Git, enter the URL of the GitHub repository (remember that we want to use HTTPS for authentication; if you want to use SSH, you need to provide a different URL), and choose a location where to store the project on your local machine. As we will start working on the project right away, also check “Open in new session”.
Git tab. To make extra sure that everything worked, let’s check the Git status of our project via the Terminal in RStudio.
Terminal in RStudio uses via Tools -> Global Options -> Terminal. If you use Windows, you should choose Git Bash (which you should have installed with Git for Windows).
git status
Now that the project is set up and in sync with the remote GitHub repository, we can start working on it. Modify the README file (just add, remove or edit a few words). If you want to, you can also create a new folder called data and copy the file ZA5667_v1-0-0_CSV_synthetic-data.csv from the workshop materials there (either via the CLI/Terminal or by copying and pasting in your file explorer). This second step is optional. We will be using this in the following sessions, but you can also copy it then.
Git.
Git tab in RStudio and their status will be indicated as modified or untracked.
Git tab.
Git tab in RStudio, write a commit message in the menu that opens up, and then click the Push button in the same menu.
Git tab in RStudio to update your local project.